package formbeans;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class ContinuousForm extends FormBean {

	private String question;
	private String dynetmlAttr;
	private String className;
	private String min;
	private String max;
	private String step;
	
	public String getQuestion() {
		return question;
	}
	public String getDynetmlAttr() {
		return dynetmlAttr;
	}
	public String getClassName() {
		return className;
	}
	public String getMin() {
		return min;
	}
	public String getMax() {
		return max;
	}
	public String getStep() {
		return step;
	}

	public void setQuestion(String question) {
		this.question = trimAndConvert(question,"<>\"");
	}
	public void setDynetmlAttr(String dynetmlAttr) {
		this.dynetmlAttr = trimAndConvert(dynetmlAttr,"<>\"");
	}
	public void setClassName(String className) {
		this.className = className;
	}
	public void setMin(String min) {
		this.min = trimAndConvert(min,"<>\"");
	}
	public void setMax(String max) {
		this.max = trimAndConvert(max, "<>\"");
	}
	public void setStep(String step) {
		this.step = trimAndConvert(step, "<>\"");
	}
	
	public List<String> checkContinuousFormErrors(){
		List<String> errors = new ArrayList<String>();
		
		if(question == null || question.length() == 0){
			errors.add("Please enter a question");
		}
		if(dynetmlAttr == null || dynetmlAttr.length() == 0){
			errors.add("Please enter dynetml attribute identifier");
		}
		if(min == null || min.length() == 0){
			errors.add("Please enter value for min");
			return errors;
		}
		if(max == null || max.length() == 0){
			errors.add("Please enter value for max");
			return errors;
		}
		if(step == null || step.length() == 0){
			errors.add("Please enter value for step");
			return errors;
		}
		
		try {
			int imin = new Integer(min);
			int imax = new Integer(max);
			Integer.parseInt(step);
			if (imin >= imax)
				errors.add("Minimum must be less than maximum");
		} catch (NumberFormatException e) {
			errors.add("Please enter valid number");
		}
		
		return errors;
	}
}